/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejb.facade;

import ejb.entity.Operations;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Trasheur
 */
@Stateless
public class OperationsFacade extends AbstractFacade<Operations> implements OperationsFacadeLocal, ejb.facade.OperationsFacadeRemote {

    @PersistenceContext(unitName = "INF3_BANQUE-ejbPU-OPERATIONS")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public OperationsFacade() {
        super(Operations.class);
    }

    @Override
    public List<Operations> findAllSource(Integer idCompte) {
        Query cq = getEntityManager().createNamedQuery("Operations.findByIdCompteSource");
        cq.setParameter("idCompteSource", idCompte);
        return cq.getResultList();
    }

    @Override
    public List<Operations> findAllCible(Integer idCompte) {
        Query cq = getEntityManager().createNamedQuery("Operations.findByIdCompteCible");
        cq.setParameter("idCompteCible", idCompte);
        return cq.getResultList();
    }

    @Override
    public List<Operations> findAllSourcesNotExec(Integer idCompte) {
        Query cq = getEntityManager().createNamedQuery("Operations.findByIdCompteSourceNotExec");
        cq.setParameter("idCompteSource", idCompte);
        return cq.getResultList();
    }

    @Override
    public List<Operations> findAllCiblesNotExec(Integer idCompte) {
        Query cq = getEntityManager().createNamedQuery("Operations.findByIdCompteCibleNotExec");
        cq.setParameter("idCompteCible", idCompte);
        return cq.getResultList();
    }

    @Override
    public Operations findLast() {
        Query cq = getEntityManager().createNamedQuery("Operations.findLast");
        return (Operations) cq.getSingleResult();
    }
}
